{extend name="public:base"}
{block name="body"}
<style>
    .upload_img_list{margin-top: 10px;}
    .upload_img_list > .img_list{display: inline-block;position: relative;margin-right:5px;background-color:#f9f9f9;border:1px solid #efefef;}
    .upload_img_list > .img_list > span{position:absolute;right:5px; top:5px; display: block; background-color:#f56c6c;height:20px;line-height: 20px;color:#fff;}
</style>
<body>
		<form class="layui-form layui-form-pane" action="">
			<div class="mainBox">
				<div class="main-container">
                   <div class="layui-row">
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">学科名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" value="{$info.name|default=''}" lay-verify="required" autocomplete="off"
                                        placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-block">
                                    <input type="number" name="sort" value="{$info.sort|default='100'}" lay-verify="required" autocomplete="off"
                                        placeholder="数字越小越靠前" class="layui-input">
                                </div>
                            </div>
                        </div>
                                             
                   </div>
                </div>
            </div>
            <div class="bottom">
            <div class="button-container">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
            </div>
		</form>
	</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery','form','upload'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let upload =layui.upload;
        let upload_box = $('#upload_box_images'); 
        let select = layui.select;
        layui.upload.render({
			elem: '#thumbBtn'
			, url: '{:url("ajax/upload")}'
			, done: function (res) {
				//如果上传失败
				if (res.code == 0) {
					return layer.msg('上传失败');
				}
				//上传成功
				
				$('#upload_box_thumb input').attr('value', res.data);		
				$('#upload_box_thumb img').attr('src', res.data);
			}
		});
       
        $(document).on('click','.img_list > span',function(){
            let that = $(this);
            
            layer.confirm('确定要删除当前图片吗', {btn: ['确定', '取消'], title: "提示"}, function (index) {
                that.closest('.img_list').remove();
                if(upload_box.find('.img_list').length ==0){
                    $('#upload_box_images').append(
                    '<div class="img_list"><img src="/assets/library/admin/images/no_img.png" style="width:150px;max-width:150px" /><input type="hidden" name="images[]" value=""></div>'
                );
                }
                layer.close(index);
            });
        })
        
        form.on('submit(form-save)', function(data) {
            $.ajax({
                url: '{:url("edit")}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code == 1) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("table-list");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
{/block}
